﻿using System.Web;
using System.Web.Services;
using System.IO;
namespace LocalCode
{

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Download : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string fileName = context.Request.QueryString["file"];
            string filePath = context.Request.QueryString["path"];
            if (!string.IsNullOrEmpty(fileName) && File.Exists(filePath + fileName))
            {
                context.Response.ContentType = "application/octet-stream";
                context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", fileName));
                context.Response.WriteFile(filePath + fileName);
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Invalid filename");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}